<?php

class PaymentController extends AppController {

	public $name = 'payment';
	
	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','toggle');

	}
	public function index() {
		$query = array(
			'fields' => array('payment.*'), 
		);
		$array = POP::exe('[@@:UM payment][@@:QU find:all]',$query);	
	    $payment = array();
	    foreach($array as $value) {
		    $payment[$value['payment']['id']] = $value['payment'];
	    }	
        $this->set('payment',$payment);      		
	}	
	public function toggle() {		
		$id = Request::get_args('id');
		$v = Request::get_args('v');
		if(!$id) {
			exit();
		}			
		$query  = array();		
		$query['keyid'] = $id;
		$safeData['payment'] = array('enabled' => $v);				
		$query['set'] = $safeData;			
		if(POP::exe('[@@:UM payment][@@:QU save]',$query)) {				
			$this->flash('更新成功！', Router::url('admin/payment/index/'));	
		}else {
			$this->flash('更新失败！', Router::url('admin/payment/index/'));
		}			
	}

}
?> 